﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
namespace 药品信息管理
{
    public partial class GYS_WRITE : Form
    {
        public GYS_WRITE()
        {
            InitializeComponent();
        }


        private void GYS_WRITE_Load(object sender, EventArgs e)
        {

            SqlConnection conn = new SqlConnection(SQL.conStr);
            string sql = "SELECT BM 编码, DH 助记符, MC 名称, ZCBM 注册编码, DZ 地址, LXR 联系人, TEL 电话, FAX 传真, POST 邮箱地址, JYXKZ 经营许可证, EMAIL 电子邮件, URL 网址 FROM YK_ZDGYS WHERE BM = '" +SQL.Gv_bm+"'" ;
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    txtbm.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                    txtzjf.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
                    txtmc.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
                    txtzcbm.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
                    txtdz.Text = ds.Tables[0].Rows[0].ItemArray[4].ToString();
                    txtlxr.Text = ds.Tables[0].Rows[0].ItemArray[5].ToString();
                    txtdh.Text = ds.Tables[0].Rows[0].ItemArray[6].ToString();
                    txtcz.Text = ds.Tables[0].Rows[0].ItemArray[7].ToString();
                    txtemail.Text = ds.Tables[0].Rows[0].ItemArray[8].ToString();
                    txtjyxkz.Text = ds.Tables[0].Rows[0].ItemArray[9].ToString();
                    txtdzyj.Text = ds.Tables[0].Rows[0].ItemArray[10].ToString();
                    txtwz.Text = ds.Tables[0].Rows[0].ItemArray[11].ToString();

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)//bm = '" + txtbm.Text + "',
        {
            db db1 = new db();
            db1.sqlcmd("update YK_ZDGYS set mc = '" + txtmc.Text + "',ZCBM = '" + txtzcbm.Text + "',DZ = '" + txtdz.Text + "',LXR = '" + txtlxr.Text + "',TEL = '" + txtdh.Text + "',FAX = '" + txtcz.Text + "',POST = '" + txtemail.Text + "',JYXKZ = '" + txtjyxkz.Text + "',EMAIL = '" + txtdzyj.Text + "',URL = '" + txtwz.Text + "' where bm='" + SQL.Gv_bm + "'");
            MessageBox.Show("成功更新！");
            this.Close();
        }

        private void GYS_WRITE_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form f = null;
            foreach (Form ff in Application.OpenForms)
            {
                
                if (ff.Name == "YP_GYS")
                {
                    f = ff;
                }

            }
            YP_GYS fff = (YP_GYS)f;
            fff.YP_GYS_Load(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            db db1 = new db();
                if (txtbm.Text == "")
                {
                    MessageBox.Show("编码不能为空！请输入编码再保存！");
                    return;
                }
                else
                {
                    string sqlcount = db1.sqlstr("select count(*) from yk_zdgys where bm = '" + txtbm.Text + "'");
                    if (sqlcount !="0")
                    { MessageBox.Show("编码重复"); }
                    else
                    {
                        db1.sqlcmd(@"insert into YK_ZDGYS (bm,mc,ZCBM,DZ,LXR,TEL,FAX,POST,JYXKZ,EMAIL,URL) values( '" + txtbm.Text + "', '" + txtmc.Text + "', '" + txtzcbm.Text + "','" + txtdz.Text + "','" + txtlxr.Text + "','" + txtdh.Text + "','" + txtcz.Text + "','" + txtemail.Text + "','" + txtjyxkz.Text + "','" + txtdzyj.Text + "','" + txtwz.Text + "')");
                        MessageBox.Show("插入成功");
                        this.Close();
                    }
                }
            
        }
    }
}